//
//  OEAddCardViewController.m
//  OneEightyNine
//
//  Created by Mac on 2019/3/7.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OEAddCardViewController.h"
#import "OECardVertifyViewController.h"
@interface OEAddCardViewController ()
@property(nonatomic, strong) UITextField                     *nameTextFiled;/**<  */
@property(nonatomic, strong) UITextField                     *cardTextFiled;/**<  */
@property(nonatomic, strong) STButton                     *typeButton;/**<  */
@property(nonatomic, strong) NSString                     *account_type;/**< <##> */
@end

@implementation OEAddCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"ADD BANK CARD";
    [self configSubView];
    // Do any additional setup after loading the view.
}
#pragma mark --subView
- (void)configSubView{
    
    __weak typeof(self) weakSelf =  self;
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    self.tableView.backgroundColor = OE_GrayColor;
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(15, 0, UIScreenWidth - 30, 40)
                                                     text:@"Please bind the cardholder“s bank card"
                                                textColor:SecendTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [footer addSubview:titleLable];
    
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(15, 44, UIScreenWidth - 30, 100)];
    whiteView.layer.cornerRadius = 10;
    whiteView.clipsToBounds = YES;
    whiteView.backgroundColor = UIColor.whiteColor;
    [footer addSubview:whiteView];
    
    
    
    self.nameTextFiled = [TMUtils textFiledWithLeftTitle:@"NAME" placeHolader:@"" rightView:nil];
    self.nameTextFiled.width = whiteView.width;
    [self.nameTextFiled st_showBottomLine];
    [whiteView addSubview:self.nameTextFiled];
    
    self.cardTextFiled = [TMUtils textFiledWithLeftTitle:@"CARD" placeHolader:@"" rightView:nil];
    self.cardTextFiled.width = whiteView.width;
    self.cardTextFiled.top = self.nameTextFiled.bottom;
    [self.cardTextFiled st_showBottomLine];
    self.cardTextFiled.keyboardType = UIKeyboardTypeNumberPad;
    [whiteView addSubview:self.cardTextFiled];
    
    STLabel * lefttitleLable = [[STLabel alloc] initWithFrame:CGRectMake(6, self.cardTextFiled.bottom, 100, 50)
                                                     text:@"TYPE"
                                                textColor:FirstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [whiteView addSubview:lefttitleLable];
    
    
    self.typeButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, whiteView.width, 50)
                                                title:@""
                                           titleColor:FirstTextColor
                                            titleFont:15
                                         cornerRadius:0
                                      backgroundColor:nil
                                      backgroundImage:nil
                                                image:nil];
//    self.typeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    self.typeButton.right = whiteView.width ;
    self.typeButton.titleEdgeInsets = UIEdgeInsetsMake(0, 50, 0, 0);
    self.typeButton.centerY = lefttitleLable.centerY;
    [self.typeButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedTypeButton];
    }];
    [whiteView addSubview:self.typeButton];
    
    whiteView.height = self.typeButton.bottom;
    
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(30, whiteView.bottom + 20, UIScreenWidth - 60 , 44)
                                                        title:@"Next"
                                                   titleColor:[UIColor whiteColor]
                                                    titleFont:18
                                                 cornerRadius:22
                                              backgroundColor:OE_LIMITE_COLOR
                                              backgroundImage:nil
                                                        image:nil];
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedNextButton];
    }];
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [footer addSubview:confimButton];
    
    footer.height = confimButton.bottom;
    self.tableView.tableFooterView = footer;
}
#pragma mark --Action Method
- (void)onSelctedTypeButton{
    NSArray * array = @[@"建设银行",@"工商银行",@"邮政银行"];
    [self.cardTextFiled resignFirstResponder];
    [self.nameTextFiled resignFirstResponder];
    STActionSheet * sheet = [STActionSheet actionSheetWithTitle:@"Chose Card Type" buttonTitles:array cancelTitle:@"Cancle" handle:^(NSInteger index) {
        if (index < array.count) {
            if (index == 0) {
                self.account_type = @"6";
            }
            if (index == 1) {
                self.account_type = @"1";
            }
            if (index == 2) {
                self.account_type = @"3";
            }
            [self.typeButton setTitle:array[index] forState:UIControlStateNormal];
        }
    }];
    [sheet show];
}
- (void)onSelctedNextButton{
    if (!self.nameTextFiled.text.length) {
        [SVProgressHUD showInfoWithStatus:@"Please input Name"];
        return;
    }
    if (!self.cardTextFiled.text.length) {
        [SVProgressHUD showInfoWithStatus:@"Please input Card"];
        return;
    }
    if (!self.account_type.length) {
        [SVProgressHUD showInfoWithStatus:@"Please chose card type"];
        return;
    }
    
    OECardVertifyViewController * vc = OECardVertifyViewController.new;
    vc.account = self.cardTextFiled.text;
    vc.bank_name = self.typeButton.currentTitle;
    vc.account_type = self.account_type;
    vc.true_name = self.nameTextFiled.text;
    [self.navigationController pushViewController:vc animated:YES];
}
@end
